package br.com.vacine.util;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import br.com.vacine.R;
import br.com.vacine.Entity.RowCalsse;

public class CustomArrayAdapter extends ArrayAdapter<RowCalsse>{

	@SuppressWarnings("unused")
	private LayoutInflater inflat;
	private List<RowCalsse> lista;
	
	public CustomArrayAdapter(Context context, List<RowCalsse> rows) {
		super(context, 0, rows);
		this.inflat = LayoutInflater.from(context);
		this.lista = rows;
	}
	
	@Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
		
		final RowCalsse row = lista.get(position);
		
		View view = LayoutInflater.from(getContext()).inflate(R.layout.list_view, null);
		
		TextView nome = (TextView)view.findViewById(R.id.textNomeVac);
		TextView data = (TextView)view.findViewById(R.id.textDataPrazoVac);
		
		CheckBox check = (CheckBox)view.findViewById(R.id.checkExcluir1);
		
		check.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

				row.setChecked(isChecked);
			}
		});
		
		
		nome.setText(row.getTextNome());
		data.setText(row.getDataVac());
		
		
		return view;
		
		
		
		
		
		
		
		
		
		
		
//		// holder pattern
//        Holder holder = null;
//        if (convertView == null)
//        {
//            holder = new Holder();
// 
//            convertView = inflat.inflate(R.layout.list_view, null);
//            holder.setTextViewTitle((TextView) convertView.findViewById(R.id.textNomeVac));
//            holder.setTextViewSubtitle((TextView) convertView.findViewById(R.id.textDataPrazoVac));
//            holder.setCheckBox((CheckBox) convertView.findViewById(R.id.checkExcluir1));
//            
//            holder.getCheckBox().setOnCheckedChangeListener(new OnCheckedChangeListener() {
//				
//				@Override
//				public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//				
//					
//				}
//			});	
//            
//            convertView.setTag(holder);
//        }
//        else
//        {
//            holder = (Holder) convertView.getTag();
//        }
// 
//        RowCalsse row = getItem(position);
//        holder.getTextViewTitle().setText(row.getTextNome());
//        holder.getTextViewSubtitle().setText(row.getDataVac());
//        return convertView;
//    }
	
    }
}
